﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
namespace _60结构体
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            Color c1 = new Color(120, 0, 12);
            System.Console.WriteLine(Color.Green.ToHex());

            Color c2 = new Color();
            //System.Console.WriteLine(c2.r);
            c2.r = 255;//可以不用new
        }
    }
    //.netFramework中的结构体   DateTime  Int Float  Double ......
    //高频率使用且体积较小的数据做成结构体,可以快速的访问,且不产生内存垃圾

    internal struct Color
    {
        public byte r;
        public byte g;
        public byte b;

        public static Color Red { get { return new Color(255, 0, 0); } }
        public static Color Green { get { return new Color(0, 255, 0); } }
        public static Color Blue { get { return new Color(0, 0, 255); } }

        public Color(byte r, byte g, byte b)
        {
            this.r = r;
            this.g = g;
            this.b = b;
        }

        public string ToHex()
        {
            return Convert.ToString(r, 16).PadLeft(2, '0') + Convert.ToString(g, 16).PadLeft(2, '0') + Convert.ToString(b, 16).PadLeft(2, '0');
        }
    }
}